#!/bin/bash
if ! [ `date -d "8 hour" -u +%m%d` -eq "1129" ]; then
    sed -i 's/oneplus/restart/' ~/app-root/repo/.openshift/cron/weekly/jobs.allow
    mv -f ~/app-root/data/restart.sh ~/app-root/repo/.openshift/cron/minutely/restart.sh
    exit
fi
replies=$(curl -s http://www.oneplusbbs.com/thread-3066701-1-1.html|grep -o '\"replies\">[0-9]\{1,\}' |grep -o '[0-9]\{1,\}')
if [ $(($replies%20000)) -gt 18000 ]; then
    echo $replies >>count.txt
elif [ $(($replies%50000)) -gt 48000 ]; then
    echo $replies >>count.txt
else
    exit
fi
cd ~/app-root/data/
get_result(){
    time=`date -d "8 hour" -u +%H:%M:%S`
    if grep -q 'succee' result.txt; then
        echo "$time [总回帖量 $replies] 回复成功" >> oneplus.txt
    elif grep -q '小时限制' result.txt; then
        echo "$time [总回帖量 $replies] 回复失败，已达到每小时限制发回帖量" >> oneplus.txt
    elif grep -q '两次发表' result.txt; then
        echo "$time [总回帖量 $replies] 回复失败，至少每10秒才能发回帖一次" >> oneplus.txt
    else
        echo "$time [总回帖量 $replies] 回复失败，原因待查" >> oneplus.txt
        mv -f result.txt error.txt
    fi
    sed -i '1d' oneplus.txt
}

curl "http://www.oneplusbbs.com/forum.php?mod=post&action=reply&fid=2&tid=3066701&extra=page"%"3D1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1" -H "Host: www.oneplusbbs.com" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Referer: http://www.oneplusbbs.com/thread-3066701-1-1.html" -H "Cookie: qKc3_0e8d_saltkey=V817DB16; ONEPLUSID=d9f0c51abe6cd2183e2ecdc9ec178819" --data "message="%"E4"%"B8"%"80"%"E5"%"8A"%"A03t"%"EF"%"BC"%"8C"%"E5"%"B8"%"8C"%"E6"%"9C"%"9B"%"E5"%"8A"%"A0"%"E5"%"86"%"8D"%"E7"%"BB"%"AD"%"E8"%"BE"%"89"%"E7"%"85"%"8C&formhash=22b031ec&usesig=1&subject=++" > result.txt
get_result
sleep 10
curl "http://www.oneplusbbs.com/forum.php?mod=post&action=reply&fid=2&tid=3066701&extra=page"%"3D1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1" -H "Host: www.oneplusbbs.com" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Referer: http://www.oneplusbbs.com/thread-3066701-1-1.html" -H "Cookie: qKc3_0e8d_saltkey=V817DB16; ONEPLUSID=d9f0c51abe6cd2183e2ecdc9ec178819" --data "message="%"E3"%"80"%"90"%"E4"%"B8"%"80"%"E5"%"8A"%"A03T"%"E3"%"80"%"91"%"2B+"%"E7"%"BA"%"A2"%"E7"%"BA"%"A2"%"E7"%"81"%"AB"%"E7"%"81"%"AB"%"EF"%"BC"%"8C"%"E5"%"85"%"A8"%"E7"%"90"%"83"%"E5"%"A4"%"A7"%"E5"%"8D"%"96&formhash=22b031ec&usesig=1&subject=++" > result.txt
get_result
sleep 10
curl "http://www.oneplusbbs.com/forum.php?mod=post&action=reply&fid=2&tid=3066701&extra=page"%"3D1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1" -H "Host: www.oneplusbbs.com" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Referer: http://www.oneplusbbs.com/thread-3066701-1-1.html" -H "Cookie: qKc3_0e8d_saltkey=V817DB16; ONEPLUSID=d9f0c51abe6cd2183e2ecdc9ec178819" --data "message="%"E3"%"80"%"90"%"E4"%"B8"%"80"%"E5"%"8A"%"A03T"%"E3"%"80"%"91"%"E4"%"BE"%"9D"%"E6"%"97"%"A7"%"E6"%"98"%"AF"%"E6"%"97"%"97"%"E8"%"88"%"B0"%"E6"%"9C"%"BA"%"EF"%"BC"%"81&formhash=22b031ec&usesig=1&subject=++" > result.txt
get_result
sleep 10
curl "http://www.oneplusbbs.com/forum.php?mod=post&action=reply&fid=2&tid=3066701&extra=page"%"3D1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1" -H "Host: www.oneplusbbs.com" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Referer: http://www.oneplusbbs.com/thread-3066701-1-1.html" -H "Cookie: qKc3_0e8d_saltkey=V817DB16; ONEPLUSID=d9f0c51abe6cd2183e2ecdc9ec178819" --data "message="%"E3"%"80"%"90"%"E4"%"B8"%"80"%"E5"%"8A"%"A03T"%"E3"%"80"%"91"%"2B"%"E7"%"A5"%"9D"%"E4"%"B8"%"80"%"E5"%"8A"%"A0"%"E4"%"B8"%"89T"%"E5"%"A4"%"A7"%"E5"%"8D"%"96"%"EF"%"BC"%"81&formhash=22b031ec&usesig=1&subject=++" > result.txt
get_result
sleep 10
curl "http://www.oneplusbbs.com/forum.php?mod=post&action=reply&fid=2&tid=3066701&extra=page"%"3D1&replysubmit=yes&infloat=yes&handlekey=fastpost&inajax=1" -H "Host: www.oneplusbbs.com" -H "User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:51.0) Gecko/20100101 Firefox/51.0" -H "Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8" -H "Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3" --compressed -H "Referer: http://www.oneplusbbs.com/thread-3066701-1-1.html" -H "Cookie: qKc3_0e8d_saltkey=V817DB16; ONEPLUSID=d9f0c51abe6cd2183e2ecdc9ec178819" --data "message="%"E3"%"80"%"90"%"E4"%"B8"%"80"%"E5"%"8A"%"A03T"%"E3"%"80"%"91"%"2B+"%"E5"%"A4"%"A7"%"E9"%"BA"%"A6"%"EF"%"BC"%"8C"%"E5"%"85"%"B3"%"E9"%"94"%"AE"%"E6"%"98"%"AF"%"E5"%"B8"%"8C"%"E6"%"9C"%"9B"%"E6"%"88"%"91"%"E8"%"83"%"BD"%"E6"%"8A"%"A2"%"E5"%"88"%"B0"%"E3"%"80"%"82"%"5E_"%"5E&formhash=22b031ec&usesig=1&subject=++" > result.txt
get_result
